<?php

namespace App\Http\Middleware;

use Closure;
use Fideloper\Proxy\TrustProxies as Middleware;

class CheckIp extends Middleware
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $curentIp = $request->ip();
        $trueIpStr = env('SUPERVISOR_ALLOW_IP');
        $trueIpArr = explode(',', $trueIpStr);
        if (!in_array($curentIp, $trueIpArr)) {
            return redirect('/');
        }
        return $next($request);
    }
}
